<?php namespace App\Services;

use App\Models\RecyclingBag;
use DB;
use App\Facades\Infra\RecyclingBagManager;
class RecyclingBagService{

	public function addRecyclingBag($data){
		RecyclingBagManager::addRecyclingBagManager($data);
	}

	public function getThisTotle(){
		$data = [
			'today' => $this->getRecyclingBagToday(),
			'thisWeek' => $this->getRecyclingBagThisWeek(),
			'thisMonth' => $this->getRecyclingBagThisMonth(),
			'thisYear' => $this->getRecyclingBagThisYear()
		];

		return $data;
	}

	public function getRecyclingBagToday(){
		return DB::selectOne(config('sql.recycling_bags.day'),[0]);
	}

	public function getRecyclingBagThisWeek(){
		return DB::selectOne(config('sql.recycling_bags.week'),[0]);
	}

	public function getRecyclingBagThisMonth(){
		// dd(DB::selectOne(config('sql.recycling_bags.month'),[0]));

		return DB::selectOne(config('sql.recycling_bags.month'),[0]);
	}

	public function getRecyclingBagThisYear(){
		return DB::selectOne(config('sql.recycling_bags.year'),[0]);
	}

	public function getRecyclingBagByDay(){

		return $this->formatSql(config('count.admin.day')-1,config('sql.recycling_bags.day'));
	}

	public function getRecyclingBagByWeek(){
		return $this->formatSql(config('count.admin.week')-1,config('sql.recycling_bags.week'));
	}

	public function getRecyclingBagByMonth(){
		return $this->formatSql(config('count.admin.month')-1,config('sql.recycling_bags.month'));
	}

	public function getRecyclingBagByYear(){
		return $this->formatSql(config('count.admin.year')-1,config('sql.recycling_bags.year'));
	}

	private function formatSql($prev,$sql){
		$array = array();
		$j = 0;
		for($i =-$prev;$i <= 0; $i+=1){
			$array[$j] = DB::selectOne($sql,[$i]);
			$j++;
		}
		return $array;
	}
}